/*
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2024-06-07 18:32:05
 * @LastEditTime: 2024-07-16 16:31:50
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 应用入口
 * @FilePath: \chu-meng\cs\main.js
 * @Copyright 版权声明
 */
// const electronReload = require('electron-reload')
// electronReload(__dirname)

const { app, BrowserWindow, Menu, Tray, nativeImage } = require("electron")

const { MENU_OPTIONS } = require('./config/menu.js')

function createWindow() {
  app.whenReady().then(() => {

    let win = new BrowserWindow({
      width: 1200,
      minWidth: 1000,
      height: 1000,
      minHeight: 800,
      icon: __dirname + '/icons/128x128.png',
      webPreferences: {
        nodeIntegration: true
      }
    })

    // const icon = nativeImage.createFromPath(__dirname + '/icons/128x128.png')
    // win.dock.setIcon(icon)
  
    // // 设置窗口图标
    // win.setIcon(__dirname + '/icons/128x128.png')
  
    // // 加载渲染进程的HTML文件，并开启热重载
    // win.loadURL('file://' + __dirname + '/index.html');
    
    win.loadFile("index.html")
  
    // // 当窗口准备就绪时打开调试面板
    // win.webContents.on('did-finish-load', () => {
    //   win.webContents.openDevTools()
    // })
  })

}
// app.whenReady().then(createWindow)

app.on('ready', () => {
  createWindow()
  // 初始化菜单
  const menu = Menu.buildFromTemplate(MENU_OPTIONS)
  Menu.setApplicationMenu(menu)
  
  // 设置托盘图标
  let tray = new Tray(__dirname + '/icons/128x128.png')
  // 可选：为图标添加右键菜单
  const contextMenu = Menu.buildFromTemplate([
    { label: '退出', click: () => app.quit() }
  ])
  tray.setToolTip('慧签通')
  tray.setContextMenu(contextMenu)
})

